/**
 * CS202 - Spring 2009 
 * Professor: Dr. Michael Peterson
 * Student: Deylo Woo (dwoo711@gmail.com)
 */
package lab5;

import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.util.ArrayList;

/**
 * A panel containing two bouncing balls.  This panel may be placed in a JFrame.
 * @author ahanes
 */
public class BallPanel extends JPanel {

    //declaring ball 1 and ball2
    //private Ball _ball;
    //private Ball _ball2;
    //declaring array of balls
    private ArrayList<Ball> _balls;
    private int _numbOfBalls;

    /** Creates a new instance of BallPanel */
    public BallPanel(int numOfBalls) {
        super();
        _numbOfBalls = numOfBalls;
        //Instantiated ball 1 and 2.
        // _ball = new Ball(this.getHeight(), this.getWidth());
        // _ball2 = new Ball(this.getHeight(), this.getWidth());
        
        //Instanciate array of balls
        _balls = new ArrayList<Ball>();
        for (int x = 0; x < _numbOfBalls; x++) {
            _balls.add(new Ball());
        }
    }

    /**
    Paints the balls at their current positions within the panel.
     */
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);                         // set color black
        g.fillRect(0, 0, this.getWidth(), this.getHeight()); // paint background

        
        //Paint ball calling ball method
        // _ball.paint(g);
        // _ball2.paint(g);
        for (Ball _b : _balls) {
            _b.paint(g);
        }
    } // end method paintComponent   

    /**
    Computes the next position for the balls and updates their positions.
     */
    public void move() {
        //panint ball move calling ball method
        // _ball.Move(getHeight(), getWidth());
        // _ball2.Move(getHeight(), getWidth());
        for (Ball _b : _balls) {
            _b.Move(getHeight(), getWidth());
        }
    } // end method move
}
